<!--
* @Description: TabNav.vue
* @Author: 王燕欣
* @Date: 2024-09-26 10:14
-->
<template>
  <div class="ku_tab_header">
    <div class="ku_tabs_nav ku_tab_scrollable">
      <div class="ku_tab_header_select" @click="openMoreClick">
        <div class="ku_tab_header_select_arrow">
          <van-icon v-if="moreState" name="arrow-up" color="#4251DF" />
          <van-icon v-else name="arrow-down" color="#4251DF" />
        </div>
      </div>
      <div class="ku_tab" v-for="(item,index) in navOption" :key="index" :class="index=== activeVal ?'active':''" @click="navClack(index)">
        <span class="ku_tab_text">
          {{ item[field] }}
          <i class="ku_tab_line"></i>
        </span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "tab_nav",
  props: {
    active: {
      type: Number,
      default: 0,
    },
    navOption: {
      type: Array, // 指定 prop 的类型为数组
      required: true, // 该 prop 是否是必传项
    },
    field: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      activeVal: 0, // 当前选中的的值
      moreState: false, // 打开更多操作
    };
  },
  created() {
    console.log(this.active);
    this.activeVal = this.active;
  },
  mounted() {},
  watch: {
    /**
     * @Description: 监测父组件选择线路变化
     * @Author: 王燕欣
     * @Date: 2024-09-26 13:12
     */
    active: {
      handler(val) {
        this.activeVal = val;
      },
      deep: true,
    },
  },
  methods: {
    // 选择线路
    navClack(params) {
      this.activeVal = params;
      this.$emit("click", params);
    },
    // 展开更多
    openMoreClick() {
      this.moreState = !this.moreState;
      this.$emit("selectClick", this.moreState);
    },
  },
};
</script>

<style lang="scss" scoped>
.ku_tab_header {
  position: fixed;
  height: 45px;
  top: 0px;
  left: 0px;
  z-index: 1;
  width: 100%;
  padding-right: 50px;
  .ku_tab_header_select {
    position: fixed;
    z-index: 1;
    top: 0px;
    right: 0px;
    width: 50px;
    height: 45px;
    background: linear-gradient(
      180deg,
      #ffffff 0%,
      rgba(255, 255, 255, 0.9) 100%
    );
    text-align: center;
    vertical-align: auto;

    .ku_tab_header_select_arrow {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 22px;
      height: 22px;
      background: rgba(66, 81, 223, 0.2);
      border-radius: 50%;
      opacity: 0.8;
    }
  }

  .ku_tabs_nav {
    padding-left: 8px;
    height: 100%;  
    background: #ffffff;
    box-shadow: 0px 1px 5px 0px rgba(0, 0, 0, 0.1);

    &::-webkit-scrollbar {
      display: none;
      width: 0 !important;
    }

    .ku_tab {
      position: relative;
      display: -webkit-box;
      display: -webkit-flex;
      display: flex;
      -webkit-box-align: center;
      -webkit-align-items: center;
      align-items: center;
      -webkit-box-pack: center;
      -webkit-justify-content: start;
      justify-content: start;
      box-sizing: border-box;
      padding: 0 4px;
      color: #646566;
      font-size: 15px;
      line-height: 20px;
      cursor: pointer;

      &.active {
        color: #4251df;
        font-weight: bold;
        font-size: 19px;

        .ku_tab_line {
          background: linear-gradient(
            90deg,
            #4251df 0%,
            rgba(66, 81, 223, 0.2) 100%
          );
        }
      }
      .ku_tab_text {
        display: inline-block;
        position: relative;
        min-width: 20px;
        .ku_tab_line {
          display: inline-block;
          width: 100%;
          min-width: 20px;
          height: 7px;
          background-color: transparent;
          border-radius: 4px;
          opacity: 0.6;
          position: absolute;
          bottom: -1px;
          left: 0px;
        }
      }
    }
  }
  .ku_tab_scrollable {
    display: flex; /* 开启 Flexbox */
    overflow-x: auto; /* 允许横向滚动 */
    white-space: nowrap; /* 防止换行 */
    .ku_tab {
      padding: 0 12px;
    }
  }
}
</style>

